<?php

require_once("../include/MySugarApplication.php");
require_once("../include/Lead.php");
session_start();
$app->checkSession('Leads/Save.php', $server_unique_key);

$id = $_REQUEST["id"];
$moduleName = $component->moduleName;

$actionType = isset($_REQUEST["actionType"]) ? $_REQUEST["actionType"] : "";

if ($actionType == "DELETE") {

	$result=$component->deleteRecord($id);

} else {

	$errors = array();


	if ($actionType == "UPDATE" && $id == "") {
		$errros["bitzer-global"] = "Cannot update when primary key is not passed";
	} else {

		$id = $_REQUEST["id"];

		$lead_source = $_REQUEST["lead_source"];
		if ($lead_source == "")
			$errors["lead_source"] = "Lead source is mandatory";
	

		$campaign_id = $_REQUEST ["campaign_id"];
		$lead_source_description = $_REQUEST ["lead_source_description"];
		$refered_by = $_REQUEST ["refered_by"];
		$salutation = $_REQUEST ["salutation"];
		$first_name = $_REQUEST ["first_name"];
		$last_name = $_REQUEST ["last_name"];
		$account_name = $_REQUEST ["account_name"];
		$title = $_REQUEST ["title"];
		$department = $_REQUEST ["department"];
		$do_not_call = (isset($_REQUEST ["do_not_call"])) ? $_REQUEST ["do_not_call"] : "";
		$assigned_user_id = $_REQUEST ["assigned_user_id"];
		$status = $_REQUEST ["status"];
		$status_description = $_REQUEST ["status_description"];
		$phone_work = $_REQUEST ["phone_work"];
		$phone_mobile = $_REQUEST ["phone_mobile"];
		$phone_home = $_REQUEST ["phone_home"];
		$phone_other = $_REQUEST ["phone_other"];
		$phone_fax = $_REQUEST ["phone_fax"];
		$email1 = $_REQUEST ["email1"];
		$primary_address_street = $_REQUEST ["primary_address_street"];
		$primary_address_city = $_REQUEST ["primary_address_city"];
		$primary_address_state = $_REQUEST ["primary_address_state"];
		$primary_address_postalcode = $_REQUEST ["primary_address_postalcode"];
		$primary_address_country = $_REQUEST ["primary_address_country"];
		$alt_address_street = $_REQUEST ["alt_address_street"];
		$alt_address_city = $_REQUEST ["alt_address_city"];
		$alt_address_state = $_REQUEST ["alt_address_state"];
		$alt_address_postalcode = $_REQUEST ["alt_address_postalcode"];
		$alt_address_country = $_REQUEST ["alt_address_country"];
		$description = $_REQUEST ["description"];
		$latitude_c = $_REQUEST["latitude_c"];
		$longitude_c = $_REQUEST["longitude_c"];
		$direction_c = $_REQUEST["direction_c"];
		$date_modified = $_REQUEST ["last_modified_on"];

		if ($do_not_call == "")
			$do_not_call = "0";

		if (count($errors) == 0) {
			$result=$component->saveRecord($id, $lead_source, $campaign_id, $lead_source_description, $refered_by,
								$salutation, $first_name, $last_name, $account_name, $title,
								$department, $do_not_call, $assigned_user_id, $status, $status_description,
								$phone_work, $phone_mobile, $phone_home, $phone_other, $phone_fax, $email1, 
								$primary_address_street, $primary_address_city, $primary_address_state, 
								$primary_address_postalcode, $primary_address_country, $alt_address_street, 
								$alt_address_city, $alt_address_state, $alt_address_postalcode, $alt_address_country, 
								$description, $latitude_c, $longitude_c, $direction_c, $date_modified);
			if ($result != "" && $result["id"] != "")
				$id = $result["id"];
		}	
	}

}

include("../include/SaveCommon.php");

?>
